﻿using App_Clinique.ClassLibrary.DbContext;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace App_Clinique.ClassLibrary.Entities
{
    public partial class Ordonnance : Document
    {
        /****************************************************************************************************
         * Methods - Inser, Update, Delete
         ***************************************************************************************************/
        public static void Create(Ordonnance ordonnance)
        {
            using (App_cliniqueContext db = new App_cliniqueContext())
            {
                db.Document.Add(ordonnance);
                db.SaveChanges();
            }
        }

        public static void Update(Ordonnance ordonnance)
        {
            using (App_cliniqueContext db = new App_cliniqueContext())
            {
                db.Entry(ordonnance).State = EntityState.Modified;
                db.SaveChanges();
            }
        }

        public static void Delete(Ordonnance ordonnance)
        {
            using (App_cliniqueContext db = new App_cliniqueContext())
            {
                db.Entry(ordonnance).State = EntityState.Deleted;
                db.SaveChanges();
            }
        }

        /****************************************************************************************************
         * Methods - Select
         ***************************************************************************************************/
        public static Ordonnance Get(Guid documentID)
        {
            Ordonnance Obj = null;

            using (App_cliniqueContext db = new App_cliniqueContext())
            {
                Obj = (from d in db.Document.OfType<Ordonnance>()
                       where d.DocumentID == documentID
                       select d).SingleOrDefault();
            }

            return Obj;
        }

        public static List<Ordonnance> GetList()
        {
            List<Ordonnance> objs = null;

            using (App_cliniqueContext db = new App_cliniqueContext())
            {
                objs = (from d in db.Document.OfType<Ordonnance>()
                        select d).ToList();
            }

            return objs;
        }

        public static List<Ordonnance> GetList(Guid patientID)
        {
            List<Ordonnance> objs = null;

            using (App_cliniqueContext db = new App_cliniqueContext())
            {
                objs = (from d in db.Document.OfType<Ordonnance>()
                        where d.PatientID == patientID
                        select d).ToList();
            }

            return objs;
        }
    }
}
